<div class="modal-header">
  <h5 class="modal-title mt-0" id="exampleModalLabel">楼层管理</h5>
  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
<!--<form class="" method="post" action="{:U('sensor_param')}" target="ajaxifr"> -->
  <input type="hidden" name="project_id" value="{$Think.request.project_id}" />
  <div class="modal-body">
    <fieldset>
      <div class="repeater-custom-show-hide">
        <div data-repeater-list="data">
          <table class="table table-centered  mb-0 ">
            <thead>
              <tr class="row">
                <th class="col-sm-7">楼层名称</th>
                <th class="col-sm-3">楼层号</th>
                <th class="col-sm-2">操作</th>
              <tr>
            </thead>
          </table>
          <empty name="list">
            <div data-repeater-item="">
              <table class="table table-centered mb-0">
                <tbody>
                  <tr class="row">
                    <td style="display: none;"><input type="text" name="id" id="id" class="form-control set_id" value="0" /></td>
                    <td class="col-sm-7"><input type="text" name="floor_name" id="floor_name" class="form-control floor_name" /></td>
                    <td class="col-sm-3"><input type="text" name="floor" id="floor" class="form-control floor" /></td>
                    <td class="col-sm-2">
                    <span data-repeater-delete="" class="btn btn-danger btn-sm">删除</span>
                    </td>
                  <tr>
                </tbody>
              </table>
            </div>
          <else />
          <volist name="list" id="vo">
            <div data-repeater-item="">
              <table class="table table-centered mb-0">
                <tbody>
                  <tr class="row">
                    <td style="display: none;"><input value="{$vo.id}" type="text" name="id" id="id" class="form-control set_id" /></td>
                    <td class="col-sm-7"><input value="{$vo.floor_name}" type="text" name="floor_name" id="floor_name" class="form-control floor_name" /></td>
                    <td class="col-sm-3"><input  value="{$vo.floor}" type="text" name="floor" id="floor" class="form-control floor" /></td>
                    <td class="col-sm-2">
                    <if condition="($demo.user_id eq $userid) OR ($demo.demo neq 1)">
                    <span data-repeater-delete="" class="btn btn-danger btn-sm">删除</span>
                    </if>
                    </td>
                  <tr>
                </tbody>
              </table>
            </div>
            </volist>
          </empty>

        </div>

        <div class="mt-2">
            <span data-repeater-create="" class="btn btn-light btn-md">
                <span class="fa fa-plus"></span> 增加
            </span>
            <if condition="($demo.user_id eq $userid) OR ($demo.demo neq 1)">
            <button type="button" class="btn btn-success" onclick="chkform(this)"><span class="fa fa-save"></span> 保存</button>
            </if>
        </div>
      </div>

      <!--end fieldset-->

    </fieldset>
  </div>
<!--</form>-->


<script>
  $(document).ready(function () {
    'use strict';


    $('.repeater-custom-show-hide').repeater({
      show: function () {
        $(this).slideDown();
        $(this).find('.set_id').val('0');
      },
      hide: function (remove) {
        if (confirm('确认要删除？')) {
          $(this).slideUp(remove);
          var id = $(this).find('.set_id').val();
          delFloor(id);
        }
      }
    });
  });

  function delFloor(id){
    var url = "{:U('delFloor')}";
    $.post(url, {id:id}, function(res){
      if(res == '1'){
        return;
      }
    });
  }

  function chkform(obj){
    var floor_names = $('.floor_name');
    var floors = $('.floor');

    for(var i=0; i<floor_names.length; i++){
      if($.trim(floor_names[i].value).length == 0){
        floor_names[i].focus();
        notify('warning', '提示', '楼层名不能为空！');
        return false;
      }

      if($.trim(floors[i].value).length == 0){
        floors[i].focus();
        notify('warning', '提示', '楼层号不能为空！');
        return false;
      }
    }

    obj.form.submit();
  }
</script>